package com.nxk.modules.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nxk.modules.content.dao.ConLinkDao;
import com.nxk.modules.content.entity.ConLink;
import com.nxk.modules.content.service.ConLinkService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConLinkServiceImpl extends ServiceImpl<ConLinkDao, ConLink> implements ConLinkService {

    @Override
    @Transactional(readOnly = false)
    public boolean save(ConLink conLink) {
        if (StringUtils.isNotBlank(conLink.getId())) {
            return super.updateById(conLink);
        } else {
            return super.save(conLink);
        }
    }

    @Override
    public IPage<ConLink> page(ConLink conLink) {
        Page<ConLink> page = new Page<ConLink>(conLink.getPageNo(), conLink.getPageSize());
        QueryWrapper<ConLink> queryWrapper = new QueryWrapper<ConLink>();
        if (StringUtils.isNotBlank(conLink.getLinkName())) {
            queryWrapper.lambda().like(ConLink::getLinkName, conLink.getLinkName());
        }
        queryWrapper.orderByAsc("sort").in("status", 1, 2);
        IPage<ConLink> result = super.page(page, queryWrapper);
        return result;

    }

    @Override
    @Transactional(readOnly = false)
    public boolean deleteById(String id) {
        return super.removeById(id);
    }
}
